//
//  SRSettingTargetViewController.m
//  SportRing
//
//  Created by Apple on 14/10/24.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRSettingTargetViewController.h"
#import "SRSettingTargetView.h"
#import "SRViewSetting.h"
#import "SRAccountNetService.h"
#import "SRDB.h"
#import "SRTaskService.h"
#import "SRManager.h"

@interface SRSettingTargetViewController () <SRSettingTargetViewDelegate>

@property (nonatomic, weak) IBOutlet SRSettingTargetView * targetView;

@end

@implementation SRSettingTargetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
    [self addLeftStringButton:NSLocalizedString(@"上一步", nil)];
    [self setCustomTitle:NSLocalizedString(@"设置目标",nil)];
}

#pragma mark - SRSettingTargetViewDelegate

- (void)didSelectTarget:(float)target
{
    SRCurrentTask * task = [SRCurrentTask findCurrentTaskCINEForMe:[SRMe currentUser]];
    [task configAttributesWithBlock:^(SRCurrentTask *aSelf) {
        aSelf.target = @(target);
    }];
    
    [SRTaskService updateTaskToDevie:task];
}

-(void)didTapDoneBtn
{
    SRMe * me = [SRMe currentUser];
    SRViewSetting * setting = [SRViewSetting sharedSetting];
    [SVProgressHUD show];
    [[SRAccountNetService updateProfileWithNickName:me.nickName
                                          birthDay:[setting.birthday formattedBy_yyyyMMdd]
                                            weight:@(setting.weight)
                                            height:@(setting.height)
                                            gender:@(setting.gender)]
     subscribeNext:^(id x) {
         [SVProgressHUD dismiss];
         [self dismissViewControllerAnimated:NO completion:nil];
     } error:^(NSError *error) {
         [SVProgressHUD showErrorWithStatus:@"上传个人信息失败"];
     }];
    
    [[SRManager sharedInstance] readyToStartUp];
}

-(void)didTapBackBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
